package com.lzx.iteam.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.lzx.iteam.R;

/**
 * Created by Megan on 16/7/27.
 */
public class CRMMainAdapter extends BaseAdapter {

    private Context mContext;
    private String[] text;
    private int[] img;

    public CRMMainAdapter(Context mContext, String[] text, int[] img) {
        this.mContext = mContext;
        this.text=text;
        this.img=img;
    }

    @Override
    public int getCount() {
        return text == null ? 0 : text.length;
    }

    @Override
    public Object getItem(int i) {
        return text == null ? null : text[i];
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.crm_main_item_layout, null);
            holder = new ViewHolder();
            holder.text = (TextView) convertView.findViewById(R.id.tv_crm_main_item_text);
            holder.image = (ImageView) convertView.findViewById(R.id.iv_crm_main_item_img);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.text.setText(text[i]);
        holder.image.setImageResource(img[i]);


        return convertView;
    }

    class ViewHolder {
        TextView text;
        ImageView image;
    }


}